package com.lmc.orderservice.service;

import com.lmc.orderservice.api.ProductApi;
import com.lmc.orderservice.mapper.OrdreMapper;
import com.lmc.orderservice.model.OrderInfo;
import com.lmc.product.model.ProductInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
@Slf4j
@Service
public class OrderService {

    @Autowired
    private OrdreMapper ordreMapper;
    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private ProductApi productApi;

    public OrderInfo selectOrderById(Integer orderId) {
        OrderInfo orderInfo = ordreMapper.selectOrderById(orderId);
        log.info("productId"+orderInfo.getProductId());
//        String url = "http://product-service/product/getProductInfo?productId=" + orderInfo.getProductId();
//        ProductInfo productInfo = restTemplate.getForObject(url, ProductInfo.class);
        ProductInfo productInfo = productApi.getProductInfo(orderInfo.getProductId());
        orderInfo.setProductInfo(productInfo);
        return orderInfo;
    }

}
